import { datas } from './fields.js'
let that
// 串口监听
export default {
	data() {
		return {
			deviceInfo: {},
			DateValue: "请选择日期",
			expectTimeHi: "请选择时间",
			adminList: [],
			selectedItem: '请选择',
			formData: {
				borrowAdminId: '',
				boxId: '',
				deviceId: '',
				expectTime: '',
				expectTimeHi: '',
				userId: '',
			},
			deviceInfo: {}
		}
	},
	computed: {},
	onShow() {
		that = this
		that.deviceInfo = uni.getStorageSync("deviceInfo")
		uni.request({
			url: '/api/h5/getAdminList',
			method: "POST",
			header: {},
			data: {},
			success: (res) => {
				that.adminList = res.data.data
			},
			fail: (err) => {
				console.error(err);
			}
		});
	},
	created() {
		that = this
	},
	onReady() {},
	onLoad(options) {
		that = this
		console.log(options)
	},
	methods: {
		onDateChange: function(e) {
			this.DateValue = e.detail.value;
			this.formData.expectTime = e.detail.value
		},
		onDateChanges: function(e) {
			this.expectTimeHi = e.detail.value;
			this.formData.expectTimeHi = e.detail.value
		},
		onPickerChange(e) {
			this.selectedItem = this.adminList[e.detail.value]['userName']
			this.formData.borrowAdminId = this.adminList[e.detail.value]['id']
		},
		submitInfo() {
			let subData = {
				borrowAdminId: this.formData.borrowAdminId,
				boxId: this.deviceInfo.boxId,
				deviceId: this.deviceInfo.id,
				expectTime: this.formData.expectTime + ' ' + that.formData.expectTimeHi + ':00',
				userId: uni.getStorageSync("userId")
			}
			uni.request({
				url: '/api/h5/deviceBorrowApply',
				method: "POST",
				header: {},
				data: subData,
				success: (res) => {
					if (res.data.code == 200) {
						uni.showModal({
							title: "温馨提示",
							content: "仪器借用申请成功",
							showCancel: false,
							confirmText: "确定",
							confirmColor: '#FF802D',
							success: function(res) {
								if (res.confirm) {
									// 用户点击确定操作
									uni.navigateBack()
								}
							}
						})
					} else {
						uni.showModal({
							title: "温馨提示",
							content: res.data.message,
							showCancel: false,
							confirmText: "确定",
							confirmColor: '#FF802D',
							success: function(res) {
								if (res.confirm) {
									// 用户点击确定操作

								}
							}
						})
					}
				},
				fail: (err) => {
					console.error(err);
				}
			});

		}
	}
}